<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 如果函数内部，变量没有声明直接赋值，也当`全局变量`看
    function fn(){
      num=10
    }
    fn()
    console.log(num)
    // 先局部后全局
    // 变量访问原则：就近原则
    let sum=10
    function fn2(){
      let sum=20
      console.log(sum) //20
    }
    fn2()
    console.log(sum) //10
  </script>
</body>
</html>